import { ready } from '@/lib/utils.ts';

import {
    setupEditablePage,
} from '@/components/table/editing';

import {
    tf,
    IDCol,
    auditStatusCol
} from '@/components/table/lib';


(function () {
    ready(() => {
        setupEditablePage({
            getDataApiUrl: '/api/user/',
            submitChangedDataApiUrl: '/api/user/',
            getOptions: (manager) => ({
                columnDefs: [
                    {
                        ...tf("username", "用户名"),
                        width: 150,
                        pinned: 'left',
                    },
                    {
                        ...tf("full_name", "姓名"),
                        width: 150,
                        pinned: 'left',
                    },
                    {
                        field: 'user_group_type',
                        headerName: gettext("类型"),
                        cellRenderer: (params: any) => params.value == 'internal_staff' ? gettext("内部员工 ") : gettext("外部人员"),
                        filterParams: {
                            textFormatter: (v: string) => {
                                if (v == "internal_staff")
                                    return gettext("内部员工")
                                else if (v == "external_personal")
                                    return gettext("外部人员")
                                return v
                            }
                        },
                        width: 120,
                    },
                    {
                        ...tf("email", "邮箱"),
                        type: 'editable',
                        onCellValueChanged: manager.onCellValueChanged,
                        width: 150,
                    },
                    {
                        ...tf("telephone", "电话"),
                        type: 'editable',
                        onCellValueChanged: manager.onCellValueChanged,
                        width: 150,
                    },
                    {
                        ...tf("company", "公司"),
                        type: 'editable',
                        onCellValueChanged: manager.onCellValueChanged,
                        width: 150,
                    },
                    {
                        field: "is_researcher",
                        headerName: gettext("是否是研究者"),
                        type: 'editable',
                        onCellValueChanged: manager.onCellValueChanged,
                        width: 120,
                    },

                    {
                        ...tf("note", "备注"),
                        type: 'editable',
                        onCellValueChanged: manager.onCellValueChanged,
                        minWidth: 200,
                        flex: 1,
                    },
                    {
                        headerName: gettext("日期"),
                        children: [
                            {
                                ...tf("last_login", "最近登陆日期"),
                                type: 'date',
                                columnGroupShow: "undefined",
                            },
                            {
                                ...tf("date_joined", "账号创建日期"),
                                type: 'date',
                                columnGroupShow: "open",
                            },
                        ]
                    },
                    auditStatusCol({})
                ]
            }),
        });
    });
})();
